Finding remainder of numbers of the form a^b